package com.younion.action.interactive.mobile;


import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.younion.action.consumer.RequestConsumer;
import com.younion.action.consumer.RequestRouter;
import com.younion.business.IFavourableService;
import com.younion.common.base.BaseAction;
import com.younion.factory.MainframeBeanFactory;

/**
 * 
 * @author wells.wong
 * 
 */
public class RouterAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	protected static final Log logger = LogFactory.getLog(RouterAction.class);
	
	private RequestRouter requestRouter;




	public String router(){
		String serviceName = request.getParameter("service");
//		if (!checkRequiredParam(request, response)) {// 验证请求是否合法
//			return null;
//		}
		String requestConsumerBeanName = requestRouter.getRequestConsumer(serviceName);
		if(StringUtils.isBlank(requestConsumerBeanName))
			logger.debug("Not register service name: "+ serviceName);
		
		try {
			RequestConsumer requestConsumer = (RequestConsumer)MainframeBeanFactory.getBeanFactory().getBean(requestConsumerBeanName);
			return requestConsumer.consume(request, response);
		} catch (Exception e) {
			logger.debug("request consumer consume service name: "+ serviceName +" with error", e);
		}
		return null;
	}


	public void setRequestRouter(RequestRouter requestRouter) {
		this.requestRouter = requestRouter;
	}

}
